//	uView 将它所有的工具类，全都放在了 uni.$u 这个对象上
const http = uni.$u.http

const getClassify = () => http.get('/api/classify/get', {
	params: {
		projectId: 152
	}
})

const getBlogByClassify = (id) => http.get('/api/blog/searchByClassifyId', {
	params: {
		id,
		projectId: 152
	}
})

const getBlogByKeywords = (keyword) => http.get('/api/blog/searchByInput', {
	params: {
		keyword,
		projectId: 152
	}
})

const createBlog = (form, token) => http.post('/api/blog/create', {
	title: form.title,
	content: form.content,
	cover: form.cover,
	classifyArr: form.classifyArr,
	projectId: 152
}, {
	header: {
		"x-token": token
	}
})


//	登录模块
const login = (phone, password) => http.post('/api/user/login', {
	phone,
	password
})

// 注册模块
const register = (registerForm) => http.post('/api/user/register', {
	phone: registerForm.phone,
	password: registerForm.password,
	name: registerForm.name,
	projectId: 152
})

//	文件模块
const upload = (data, token) => http.upload('/api/imgUpload', {
	header: {
		"x-token": token
	},
	formData: {
		file: data
	}
})
// 获取用户信息模块
const userMsg = (id, token) => http.get('/api/user/searchUser', {
	header: {
		"x-token": token
	},
	params: {
		id,
		projectId: 152
	}
})

// 点赞/取消点赞博客
const isLoveBlog = (id, token) => http.post('/api/blog/likeBlog', {
		id,
		projectId: 152
	}, {
		header: {
			"x-token": token
		},
	}

)

// 获取点赞过的博客
const getLoveBlog = (token) => http.get('/api/user/getLikeBlog', {
	header: {
		"x-token": token
	}
})
// 获取所有博客（似乎不需要它）
const getAllBlogs = () => http.get('/api/blog/getAllBlog', {
	params: {
		projectId: 152,
		limit: 50
	}
})
// 根据id获取博客
const acIdBlog = (id, token) => http.get('/api/blog/search', {
	header: {
		"x-token": token
	},
	params: {
		id,
		projectId: 152
	}
})
// 关注/取消关注用户
const isLoveUser = (id, token) => http.post('/api/user/follow', {
	id,
	projectId: 152
}, {
	header: {
		"x-token": token
	}
})

// 发布评论
const publishComment = (blogId, token, content, parentCommentId) => http.post('/api/comment/create', {
	blogId,
	projectId: 152,
	content,
	parentCommentId
}, {
	header: {
		"x-token": token
	}
})
// 获取当前博客评论
const getCurrentComment = (id) => http.get('/api/comment/get', {
	params: {
		id,
		projectId: 152
	}
})
// 点赞评论
const isLoveComment = (commentId, blogId, token) => http.post('/api/comment/like', {
	commentId,
	blogId,
	projectId: 152
}, {
	header: {
		"x-token": token
	}
})

// 获取用户自己的博客
const getSelfBlog = (token) => http.get('/api/blog/getMyBlog', {
	header: {
		"x-token": token
	},
	params: {
		projectId: 152,
		limit: 50,
		offset: 0
	}
})
// 获取博客浏览历史
const getHistory = (token) => http.get('/api/blog/getHistory', {
	header: {
		"x-token": token
	},
	params: {
		projectId: 152,
		limit: 50,
		offset: 0
	}
})
// 编辑个人信息
const editUserMsg = (name, avatar, desc, token) => http.put('/api/user/edit', {
	name,
	avatar,
	desc,
	projectId: 152
}, {
	header: {
		'x-token': token
	}
})
export {
	getClassify,
	getBlogByClassify,
	getBlogByKeywords,
	createBlog,
	login,
	upload,
	register,
	userMsg,
	isLoveBlog,
	getLoveBlog,
	getAllBlogs,
	isLoveUser,
	acIdBlog,
	publishComment,
	getCurrentComment,
	isLoveComment,
	getSelfBlog,
	getHistory,
	editUserMsg
}
